﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class user_register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnRegiser_Click(object sender, EventArgs e)
    {
        Customer objCus= new Customer();
        objCus.Firstname = txtFirstname.Text;
        objCus.Lastname = txtLastname.Text;
        //parse string date
        try
        {
            objCus.Birthday = DateTime.Parse(txtBirthdate.Text);
        }
        catch (Exception)
        { }
        //checked gender
        if (DropDownListGender.SelectedIndex ==1)
            objCus.Gender = true;
        else if (DropDownListGender.SelectedIndex == 2)
            objCus.Gender = false;
        objCus.Email = txtEmail.Text;
        objCus.Phone = txtPhone.Text;
        objCus.Address = txtAddress.Text;
        objCus.Password = txtPassword.Text;
        CustomerBus CustomerBus = new CustomerBus();
        if (CustomerBus.addCustomer(objCus))
        {
            txtEmail.Text = "";
            txtAddress.Text = "";
            txtBirthdate.Text = "";
            txtFirstname.Text = "";
            txtLastname.Text = "";
            txtPhone.Text = "";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Messages", "<script>alert('Register new Customer success!')</script>", false);
            Response.Redirect("notify.aspx?msg=Thank for Register");
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, typeof(Page), "Messages", "<script>alert('Register faild!')</script>", false);
        }
    }
 
}